import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import path from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { fileURLToPath } from "url";
const pathResolve = (dir) => resolve(__dirname, dir);
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [resolve(process.cwd(), "src/assets/svg")],
      symbolId: "icon-[dir]-[name]",
    }),
  ],
  // 配置scss
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "scss",
      patterns: [],
    },
  },
  server: {
    port: 8080, //默认启动时的端口号
    open: true, //自动打开默认浏览器
    cors: true, //允许跨域
  },
  resolve: {
    alias: {
      // @ 替代为 src   vite
      "@": path.resolve(__dirname, "src"),
      // "@": fileURLToPath(new URL("./src", import.meta.url)),
      /*    // @ 替代为 src
      "@": resolve(__dirname, "src"),
      // @component 替代为 src/component
      "@components": resolve(__dirname, "src/components"), */

      // '@': pathResolve('./src') //配置'@'指向'src'
    },
  },
});
